'use strict';
const db=uniCloud.database()
const $ = db.command.aggregate
exports.main = async (event, context) => {
	
	const {
		user_id,
		article_id,
		pageSize = 5,
		page = 1
	}=event
	
		const list = await db.collection('article')
		.aggregate()
		.match({
			_id:article_id
		})
		.unwind('$comments')//文档拆分
		.project({
			_id:0,
			comments:1
		})
		.replaceRoot({//重新定义根节点
			newRoot:"$comments"
		})
		.skip(pageSize*(page-1))
		.limit(pageSize)
		.end()
	
	
	//返回数据给客户端
	return {
		code:200,
		message:'数据请求成功',
		data:list.data
	}
};
